package com.itkjb.leisurely.center.sys.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.itkjb.leisurely.center.sys.mapper.SysDepartmentMapper;
import com.itkjb.leisurely.center.sys.model.SysDepartmentModel;
import com.itkjb.leisurely.center.sys.service.ISysDepartmentService;
import com.itkjb.leisurely.core.base.service.impl.BaseServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 组织结构 服务实现类
 * </p>
 *
 * @author itkjb.com
 * @since 2020-07-02
 */
@Service
public class SysDepartmentServiceImpl extends BaseServiceImpl<SysDepartmentMapper, SysDepartmentModel> implements ISysDepartmentService {


    @Override
    public List<SysDepartmentModel> findUserDepsByUserId(String userId) {
        return this.baseMapper.findUserDepsByUserId(userId);
    }

    /**
     * wrapper 组装器，构造条件查询
     *
     * @param wrapper
     * @param model   条件
     * @author itkjb.com
     * @date 2020-07-02
     **/
    @Override
    protected void assembleWrapper(QueryWrapper<SysDepartmentModel> wrapper, SysDepartmentModel model) {

        wrapper.lambda().eq(StringUtils.isNotBlank(model.getId()), SysDepartmentModel::getId, model.getId());
        // 组织名字
        wrapper.lambda().eq(StringUtils.isNotBlank(model.getDepName()), SysDepartmentModel::getDepName, model.getDepName());
        // 组织机构代码
        wrapper.lambda().eq(StringUtils.isNotBlank(model.getDepCode()), SysDepartmentModel::getDepCode, model.getDepCode());

    }

    /**
     * wrapper 组装器，组装list查询时，查询的列
     *
     * @param wrapper
     * @param model
     * @return void
     * @author itkjb.com
     * @date 2020-07-02
     * @since 2020-07-02
     **/
    @Override
    protected void buildListSelectColumns(QueryWrapper<SysDepartmentModel> wrapper, SysDepartmentModel model) {
        buildCommonSelectColumns(wrapper, model);
    }

    /**
     * 组装列表查询的列（字段）
     *
     * @param wrapper
     * @param model
     * @date 2020-07-02
     */
    protected void buildCommonSelectColumns(QueryWrapper<SysDepartmentModel> wrapper, SysDepartmentModel model) {
        wrapper.lambda().select(
                // id
                SysDepartmentModel::getId,
                // 组织名字
                SysDepartmentModel::getDepName,
                // 组织机构代码
                SysDepartmentModel::getDepCode,

//            SysDepartmentModel::getRemark,
                SysDepartmentModel::getCreateTime
        );
    }
}
